package cn.sdormitory.controller.basedata;

import cn.sdormitory.basedata.entity.BSubject;
import cn.sdormitory.basedata.service.BSubjectService;
import cn.sdormitory.common.annotation.SysLog;
import cn.sdormitory.common.api.CommonPage;
import cn.sdormitory.common.api.CommonResult;
import cn.sdormitory.common.enums.BusinessType;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @className: BSubjectController
 * @author: Alex
 * @date: 2024/12/9
 **/
@RestController
@Api(tags = "Basedata-subject=> 专业管理")
@RequestMapping("/basedata/bsubject")
public class BSubjectController {
	
	@Resource
	private BSubjectService bSubjectService;
	
	@ApiOperation("list => 查询专业列表")
	@GetMapping(value = "/list")
	public CommonResult<CommonPage<BSubject>> list(@RequestParam Map<String, Object> params) {
		IPage<BSubject> page = bSubjectService.getPage(params);
		return CommonResult.success(CommonPage.restPage(page));
	}
	
	@ApiOperation("list => 查询专业列表")
	@GetMapping(value = "/listAll")
	public CommonResult<List<BSubject>> listAll() {
		List<BSubject> resultList = bSubjectService.getSubjectList();
		return CommonResult.success(resultList);
	}
	
	@PostMapping("/createOrUpdateSubject")
	public CommonResult createOrUpdateCourse(@RequestBody BSubject bSubject){
		int flag = bSubjectService.createOrUpdateSubject(bSubject);
		if(flag > 0){
			return CommonResult.success();
		}else {
			return CommonResult.failed();
		}
	}
	
	@DeleteMapping("/deleteById/{id}")
	public CommonResult deleteById(@PathVariable("id") Long id){
		int result = bSubjectService.deleteByIds(id);
		if(result > 0){
			return CommonResult.success();
		}else {
			return CommonResult.failed();
		}
	}
	
	@ApiOperation("update/status/{id} => 修改专业状态")
	@PutMapping(value = "/update/status/{id}")
	public CommonResult<Integer> update(@PathVariable Long id, String status) {
		int count = bSubjectService.updateStatus(id, status);
		if (count > 0) {
			return CommonResult.success(count);
		}
		return CommonResult.failed();
	}
}
